﻿using Lidgren.Network;
using Paintball.Network;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Paintball.Abstraction
{
    public class PaintballUpdatePacket : IDataPacket
    {
        //Fields
        public GameState CurrentGameState;
        public List<Player> PlayerData;
        
        //Construct
        public PaintballUpdatePacket()
        {
            this.CurrentGameState = GameState.Lobby;
            this.PlayerData = new List<Player>();
        }
        
        //Methods
        public void Encode(NetOutgoingMessage outMsg)
        {
            outMsg.Write((int)CurrentGameState);
            outMsg.Write((int)PlayerData.Count);
            foreach (Player player in PlayerData)
                player.Write(outMsg);
        }
        public void Decode(NetIncomingMessage incMsg)
        {
            CurrentGameState = (GameState)incMsg.ReadInt32();
            int num = incMsg.ReadInt32();
            PlayerData = new List<Player>(num);
            for (int i = 0; i < num; i++)
            {
                Player t = new Player();
                t.Read(incMsg);
                PlayerData.Add(t);
            }
        }
    }
}
